/*
 * This file is part of Super Luigi Bros.
 * Super Luigi Bros is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Super Luigi Bros is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Super Luigi Bros.  If not, see <http://www.gnu.org/licenses/>.
 */
package luigibros.displayComponents;


import java.awt.Image;
import java.io.IOException;
import java.util.List;
import luigibros.data.ImageStore;
/** This class controls/loads the images for each
 * coresponding sprite.
* @author AbsentFEAR420 (Brandon Henrikson)
*/
public class Sprite 
{
	private String className;
	private String stateName;
	private String actionName;
	private List<Image> frames;
	private int step;
	private ImageStore store;
	
	
	
    /** <code>Sprite</code> will set the class
     *  name to whatever is sent to it.
     * 
     * @param className
     */
	 public Sprite(String className) 
	 {  
		 this.className = className;
	 }
	 
	/** <code>loadAction</code> will receive
	 *  the action name and load via the 
	 *  <code>loadImages</code> method.
	 *  of the <code>ImageStore</code> class
	 * 
	 * @param action
	 */
	public void loadAction(String action) 
	{
		actionName = action.toLowerCase();	
		frames = store.loadImages(className, stateName, actionName);
	}
	/** <code>setStep</code> receives the step.
	 * 
	 * @param _step
	 */
	public void setStep(int _step)
	{
		step = _step;
	
	}
	/**<code>step</code>increments the step 
	 * by 1
	 * @param none
	 */
	 
	public void step()
	{
		step = step++;
	}
	/**<code>setState</code> receives the state
	 *  and loads via the <code>preload</code> 
	 *  method of the <code>ImageStore</code>
	 *  class . 
	 * 
	 * @param state
	 * @throws IOException 
	 */
	public void setState(String state) throws IOException
	{
		stateName = state.toLowerCase();		
		store.preload(className, stateName);
	}	
	/**<code>hasNextStep</code> returns 
	 * true if there is still room on the 
	 * screen to move, false if the end of
	 * the screen has been reached.
	 * 
	 * @return True/False
	 */
	public boolean hasNextStep()
	{
		return (step < frames.size()); 	
	}
	/**<code>getImage</code> returns the image
	 * that coresponds with the step that the
	 * sprite is on.
	 * 
	 * @return image of the step
	 */
	public Image getImage()
	{
		return frames.get(step);	
	}
}
